package com.itheima.controller;

<<<<<<< HEAD
import com.fasterxml.jackson.databind.ObjectMapper;
import com.itheima.service.impl.CityServiceImp;
import com.itheima.service.impl.ProductServiceImpl;
=======
import com.itheima.service.OrdersService;
import com.itheima.service.impl.OrdersServiceImpl;
>>>>>>> 87a0f68c2b3b7de3b37de1968a6eac4ab534cee5

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Method;

public class BaseServlet extends HttpServlet {
<<<<<<< HEAD
    ProductServiceImpl product;
    CityServiceImp city;
    ObjectMapper obj;
    public void init() throws ServletException {
        product=new ProductServiceImpl();
         city = new CityServiceImp();
        obj = new ObjectMapper();
=======
    public OrdersService ordersService;

    public void init() throws ServletException {
        ordersService = new OrdersServiceImpl();
>>>>>>> 87a0f68c2b3b7de3b37de1968a6eac4ab534cee5
    }

    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1、获取URI
        String uri = req.getRequestURI();
        String methodName = uri.substring(uri.lastIndexOf("/") + 1);
        //获取方法对象
        try {
            Method method = this.getClass().getDeclaredMethod(methodName, HttpServletRequest.class, HttpServletResponse.class);
            method.setAccessible(true);
            method.invoke(this, req, resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
